GBML manual / Drawing

draw_sprite_3d

Like draw_sprite, but the picture curves away from you, as if it were wrapped round a barrel or tipped back like a sign: the top and bottom of it shrink back and the middle stays full size. shape picks the look: SPRITE_BULGE, SPRITE_LEAN_BACK and SPRITE_LEAN_FORWARD choose which part of the picture shrinks, and SPRITE_DRUM fixes a lens on the middle of the screen and the sprite slides through it. depth says how much, from 1 to 3 (1 is gentle, 3 is deep); for SPRITE_DRUM it is how tight the lens is, from 1 to 6. 0 draws the sprite flat.

Works differently on Game Boy - The Game Boy narrows the picture on some lines by moving its two sprite pieces toward each other (the middle is covered, not squeezed), a drum or a band hides it outside the lens; 16 pixels wide at most, one picture at a time; the size is not used.

Works differently on Game Boy Color - The Game Boy Color narrows the picture on some lines by moving its two sprite pieces toward each other (the middle is covered, not squeezed), a drum or a band hides it outside the lens; 16 pixels wide at most, one picture at a time; the size is not used.

Sega Genesis: not available

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_sprite_3d(spr, x, y, frame, shape, depth)

Arguments

NameType
sprsprite
xreal
yreal
frameint
shapesprite_shape
depthint

Returns

Nothing.

Description

Draws a sprite that curves away from you, as if it were wrapped round a barrel or tipped back like a sign. The top and bottom of the picture shrink back and the middle stays full size. It is draw_sprite with a third dimension, and it does for a sprite what draw_text_3d does for a line of text.

A real capture - four striped lighthouses side by side. The first is drawn flat with draw_sprite. The second is a SPRITE_BULGE at depth 3 and is narrower at the top and bottom than in the middle, like a barrel. The third is SPRITE_LEAN_BACK, narrow at the top and wide at the bottom, like a sign tipped back. The fourth is SPRITE_LEAN_FORWARD, wide at the top and narrow at the bottomA real capture - four striped lighthouses side by side. The first is drawn flat with draw_sprite. The second is a SPRITE_BULGE at depth 3 and is narrower at the top and bottom than in the middle, like a barrel. The third is SPRITE_LEAN_BACK, narrow at the top and wide at the bottom, like a sign tipped back. The fourth is SPRITE_LEAN_FORWARD, wide at the top and narrow at the bottom
A real capture - four striped lighthouses side by side. The first is drawn flat with drawsprite. The second is a SPRITEBULGE at depth 3 and is narrower at the top and bottom than in the middle, like a barrel. The third is SPRITELEANBACK, narrow at the top and wide at the bottom, like a sign tipped back. The fourth is SPRITELEANFORWARD, wide at the top and narrow at the bottom

Left to right: a flat draw_sprite, then the same sprite with SPRITE_BULGE, SPRITE_LEAN_BACK and SPRITE_LEAN_FORWARD, all at depth 3. A tall striped lighthouse stands in for the example's spr_doc_tower, because a curve is much easier to see on something tall: the calls and the numbers are the same. (The console can only do two of these at once, see "What it costs" below, so the four pictures are four different moments, cut out and put side by side.) Real pictures from a Game Boy Advance ROM.

x and y are a place in the room, counted from the room's top-left corner, and the sprite is drawn with its origin on that spot, exactly like draw_sprite. It is cached the same way too: call it every frame the sprite should stay on screen, and stop calling it to let it go.

shape says which part of the picture shrinks away:

They are the same four curves a line of text has (TEXT_BULGE, TEXT_LEAN_BACK and the rest), with names that say what is being drawn. A TEXT_ name in a sprite call is a mistake, and the checker tells you so.

How deep: depth 0 to 3

depth says how much, as a whole number. A number past the top is held to the top, and a number below 0 is read as 0.

A real capture - the same striped lighthouse drawn flat, and then with SPRITE_BULGE at depth 1, 2 and 3, left to right. The deeper the depth, the narrower the top and bottom of the lighthouse get compared with its middleA real capture - the same striped lighthouse drawn flat, and then with SPRITE_BULGE at depth 1, 2 and 3, left to right. The deeper the depth, the narrower the top and bottom of the lighthouse get compared with its middle
A real capture - the same striped lighthouse drawn flat, and then with SPRITE_BULGE at depth 1, 2 and 3, left to right. The deeper the depth, the narrower the top and bottom of the lighthouse get compared with its middle

The same bulge at every depth, from flat on the left to depth 3 on the right.

A real capture, 12 frames played in a loop - a plain striped lighthouse on the left stands still while the one on the right is a SPRITE_BULGE whose depth goes 1, 2, 3, 2, 1, 0 and round again, so it swells from a gentle barrel to a deep one and back to flat. The first frame, which is all a viewer that cannot animate shows, is depth 1.A real capture, 12 frames played in a loop - a plain striped lighthouse on the left stands still while the one on the right is a SPRITE_BULGE whose depth goes 1, 2, 3, 2, 1, 0 and round again, so it swells from a gentle barrel to a deep one and back to flat. The first frame, which is all a viewer that cannot animate shows, is depth 1.
A real capture, 12 frames played in a loop - a plain striped lighthouse on the left stands still while the one on the right is a SPRITE_BULGE whose depth goes 1, 2, 3, 2, 1, 0 and round again, so it swells from a gentle barrel to a deep one and back to flat. The first frame, which is all a viewer that cannot animate shows, is depth 1.

The same call with only depth changing (the line under the picture says which): twelve real pictures played in a loop, each held for about a third of a second. The plain lighthouse on the left never changes. A viewer that does not animate shows the first frame.

Why only 3? The deeper curves of draw_text_3d (depths 4, 5 and 6) are made for letters. Letters stop a few rows short of the top and bottom of their box, so a curve can squeeze those empty rows as hard as it likes. A picture that runs right to the edge of its box would have its edges squeezed into thin slivers, so a bulge or a lean on a sprite is held to depth 3. The one exception is SPRITE_DRUM: there depth goes up to 6, because it is the width of a lens fixed on the screen and does not care what the picture is.

The shrinking is real, not a trick of the art. Every row of the screen is drawn at its own size, and every row of the picture is still shown. It is squeezed into fewer rows toward the curved edges and never cut, so the sprite comes out a little shorter than the flat one, never taller. The curve runs from the middle of the picture to its edge, and it follows the sprite up and down the screen to the nearest two rows.

Sprites that are 8, 16, 32 or 64 pixels tall work. A bigger picture is made of several sprites, and would need several calls.

It is for a sprite you draw with this call, not for an object's own sprite when it draws itself, and it does not turn the picture: there is no angle. To change the size of it, use draw_sprite_3d_scaled.

What it costs

Exactly what a 3D text costs, out of the same pool. A 3D sprite uses one of the 32 matrices and two of the 8 row-by-row effects the console has, and 640 bytes of memory, for as long as the call keeps being made. Nothing in the cartridge: there is no new table, and a game that never calls this does not carry the code.

A room change keeps two of the eight row-by-row effects for itself, so there are six left for you:

A sky from screen_backdrop takes one of the six too, and the game counts them all together, so a room change always has its two. A fourth 3D thing does not fit, and the console will not draw it curved.

Ask for more than there is and the game stops, in a development build, with a message that names every call holding a slot - they are numbered from 0 in the order they are written in an object's event, a 3D sprite is named by where it is drawn and a 3D text by its first letters. The sprite has already been drawn flat when it stops, and a release build, which has no such stop, simply shows it flat. The curve never fails to appear: you are told.

The 160 rows of numbers are worked out in memory, not read from the cartridge. They are worked out again only on a frame where the sprite moved up or down two rows, or its shape or depth changed. That takes about 11,000 cycles, which is 4% of one frame (the console has about 280,000 to spend on a frame). A sprite that sits still, or only moves sideways, costs nothing after its first frame.

Example

draw_sprite_3d(spr_doc_tower, x, y, 0, SPRITE_BULGE, 3);

The tower, bulging like a barrel, at depth 3.

var tilt = 0;

if (btn_held(BTN_A)) { tilt = 3; }

draw_sprite_3d(spr_doc_tower, x, y, 0, SPRITE_LEAN_BACK, tilt);

A sprite that leans back only while A is held. With tilt at 0 it is the plain flat sprite and the effect costs nothing; the moment it becomes 3 the top of the picture sweeps away from you.

draw_sprite_3d(spr_doc_tower, x, y + wave(-40, 40, 120, 0), 0, SPRITE_DRUM, 3);

The tower sliding up and down through a lens in the middle of the screen, getting smaller as it nears the top or the bottom of it. See SPRITE_DRUM.

On the GBA

Costs ONE of the hardware’s 32 affine matrices and TWO of the console’s 8 row-by-row (H-Blank) effects, for as long as the call keeps being made, plus 640 bytes of memory (nothing in the cartridge) and about 11,000 cycles (4% of a frame) on a frame where it moved up or down two rows or changed size, shape or depth. That is exactly what a 3D text costs, out of the same pool: a room transition keeps two of the eight for itself, so at most three 3D things (a text or a sprite) fit on screen at once, and a rippling sprite takes one of the same six. Asking for more than there is stops the game with a message that names every call holding a slot (the plain sprite has already been drawn when it stops, and a release build, which has no such stop, simply draws it flat). depth 0 draws a plain sprite and costs nothing. A bulge or a lean is held to depth 3 (a bigger number is treated as 3): the deeper curves of draw_text_3d are made for letters, which leave empty rows above and below them, and would crush a picture that runs to the edge of its box. The curve runs from the middle of the picture to its edge and follows the sprite to the nearest two rows. Every row of the picture is still drawn - it is squeezed into fewer rows of the screen, not cut - so the sprite comes out a little shorter than the plain one, never taller. Sprites 8, 16, 32 and 64 pixels tall work. With SPRITE_DRUM the lens belongs to the screen, not to the sprite: a sprite whose middle is outside the lens is not drawn at all (it keeps its matrix and its two row-by-row effects until you stop calling), and depth is how tight the lens is. The sprite is not turned or tinted: use draw_sprite_3d_scaled to change its size.

See also: draw_spritedraw_sprite_3d_scaleddraw_text_3ddraw_sprite_rippledraw_sprite_scaled